package 笔试;

import java.util.Scanner;

public class 三六零_快速排序 {
    public static int n = 0;
    public static int[] arr = {};
    public static int k = 0;
    public static int[] K = {};

    public static int x = 0;

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        scan.nextLine();
        arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }
        scan.nextLine();
        k = scan.nextInt();
        scan.nextLine();
        K = new int[k];
        for (int i = 0; i < k; i++) {
            K[i] = scan.nextInt();
        }

        quickSort(arr);

        for (int i = 0; i < n; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    public static void quickSort(int[] array) {
        quick(array, 0, array.length);
    }

    private static void quick(int[] array, int left, int right) {
        if(x == k) {
            return;
        }
        int j = 0;
        for (; j < array.length; j++) {
            if(K[x] == array[j]) {
                x++;
                break;
            }
        }
        int minValIndex = j;
        swap(array, left, minValIndex);

        int pivot = partition(array, left, right);
        quick(array, left, pivot-1);
        quick(array, pivot+1, right);

    }



    private static int partition(int[] array, int left, int right) {
        int temp = array[left];
        while(left < right) {
            while (left < right && array[right] > temp) {
                right --;
            }
            array[left] = array[right];
            while (left < right && array[left] < temp) {
                left++;
            }
            array[right] = array[left];
        }
        array[left] = temp;
        return left;
    }

    public static void swap(int[] array,int i,int j) {
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }
}
